package com.zjl.cms.util;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonUtil {

	public static JSONObject stringToJson(String body) {

		JSONObject result = new JSONObject();
		if (body != null && !body.equals("")) {
			result = JSONObject.fromObject(body);
		}

		return result;
	}

	public static JSONArray stringToJsonArry(String body) {

		JSONArray result = new JSONArray();
		if (body != null && !body.equals("")) {
			result = JSONArray.fromObject(body);
		}

		return result;
	}
	
	public static String objectToJsonString(Object body) {

		JSONObject result = new JSONObject();
		if (body != null ) {
			try {
				result = JSONObject.fromObject(body);
				return result.toString();
			} catch (Exception e) {
				return JSONArray.fromObject(body).toString();
			}
		}

		return null;
	}
}
